package demo1;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.concurrent.Semaphore;

public class Test {
    public static void main2(String[] args) {

    }
    public static void main(String[] args) throws ClassNotFoundException,
            NoSuchMethodException, InvocationTargetException,
            InstantiationException, IllegalAccessException {
        Class clazz = Class.forName("demo1.SEnum");
        Constructor con = clazz.getDeclaredConstructor(String.class,int.class,String.class, String.class);
        con.setAccessible(true);
        SEnum o = (SEnum) con.newInstance("黑夜",9,"晴天", "开心");
        //此时通过反射新建了一个枚举对象
        System.out.println(o);
    }

    public static void main1(String[] args) {
        System.out.println(SEnum.SPRING);
        SEnum[] sEnum = SEnum.values();
        for (SEnum anEnum : sEnum) {
            System.out.println(anEnum.ordinal());
            //获取枚举成员的索引位置
        }
        System.out.println("====");
        SEnum v1 = SEnum.valueOf("SPRING");
        System.out.println(v1);
        /*SEnum v2 = SEnum.valueOf("eheh");//前提是枚举类型中必须包含该常量
        System.out.println(v2);*/

        //因为 Enum 类实现了 Comparable 接口
        System.out.println(SEnum.SPRING.compareTo(SEnum.SUMMER));//比较

    }
}
